<html>
<head><meta charset="utf-8"><title>ProjectionKinds · t-compiler/wg-rfc-2229 · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/index.html">t-compiler/wg-rfc-2229</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html">ProjectionKinds</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="201923521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/201923521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#201923521">(Jun 25 2020 at 01:27)</a>:</h4>
<p>Continuining the conversation from here: <a href="#narrow/stream/189812-t-compiler.2Fwg-rfc-2229/topic/refactoring.20.60hir.3A.3APlace.60.20and.20.60hir_id.60/near/200247505">https://rust-lang.zulipchat.com/#narrow/stream/189812-t-compiler.2Fwg-rfc-2229/topic/refactoring.20.60hir.3A.3APlace.60.20and.20.60hir_id.60/near/200247505</a></p>



<a name="201923614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/201923614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#201923614">(Jun 25 2020 at 01:28)</a>:</h4>
<p>Can we get some more details on the ProjectionsKinds here: <a href="https://github.com/rust-lang/project-rfc-2229/blob/master/hir-place-target.md">https://github.com/rust-lang/project-rfc-2229/blob/master/hir-place-target.md</a></p>



<a name="201923645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/201923645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#201923645">(Jun 25 2020 at 01:29)</a>:</h4>
<p>Especially more ideas about what Field and VariantIdx is? <br>
We were thinking some around using <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckTables.html#structfield.field_indices">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckTables.html#structfield.field_indices</a> , not sure how  to really use it rn.</p>



<a name="202028934"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202028934" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202028934">(Jun 25 2020 at 21:42)</a>:</h4>
<p><span class="user-mention" data-user-id="281950">@Aman Arora</span> field and variant index refers to the way the compiler represents structs/enums, which are unified into one concept (a "ADT"). You can read about the ADT stuff in <a href="https://rustc-dev-guide.rust-lang.org/ty.html?highlight=adt#adts-representation">this section of the rustc-dev-guide</a></p>



<a name="202028988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202028988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202028988">(Jun 25 2020 at 21:43)</a>:</h4>
<p>but for an enum the "variants" are the, well, variants of the enum: e.g., for option it would be <code>Some</code> and <code>None</code></p>



<a name="202029000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202029000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202029000">(Jun 25 2020 at 21:43)</a>:</h4>
<p>and the field index is the index within a variant. So if you have <code>Some(v)</code> the <code>v</code> is the field 0</p>



<a name="202029009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202029009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202029009">(Jun 25 2020 at 21:43)</a>:</h4>
<p>a struct is basically an enum with just one variant</p>



<a name="202029067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202029067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202029067">(Jun 25 2020 at 21:43)</a>:</h4>
<p>so the idea would be that <code>foo.f</code> is basically going to be the index of <code>f</code> combined with the index 0 for the variant (because <code>foo</code> must be a struct)</p>



<a name="202029118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202029118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202029118">(Jun 25 2020 at 21:44)</a>:</h4>
<p>but when you get refs to fields through pattern matching, you can get other things</p>



<a name="202029214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202029214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202029214">(Jun 25 2020 at 21:45)</a>:</h4>
<p>e.g., </p>
<div class="codehilite"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="nb">Some</span><span class="p">(</span><span class="nb">String</span>::<span class="n">new</span><span class="p">());</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">p</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="cm">/* p here is a place that points into `*x` */</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="202650762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202650762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202650762">(Jul 02 2020 at 05:06)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> Still not sure where we would use ProjectionKind::Field wtih a variant other tham 0? </p>
<p>Will it be something like here: <a href="https://gist.github.com/rust-play/aaa6a922cf0a6392b80aeedbba91f587">https://gist.github.com/rust-play/aaa6a922cf0a6392b80aeedbba91f587</a>?</p>
<p>And we handle this in TupleStruct? <a href="https://github.com/rust-lang/rust/blob/9491f18c5de3ff1c4bf9c3fdacf52d9859e26f7c/src/librustc_typeck/mem_categorization.rs#L657">https://github.com/rust-lang/rust/blob/9491f18c5de3ff1c4bf9c3fdacf52d9859e26f7c/src/librustc_typeck/mem_categorization.rs#L657</a>? </p>
<p>If so how do we get the variant index and field index in this case?</p>



<a name="202674543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202674543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202674543">(Jul 02 2020 at 11:11)</a>:</h4>
<p><span class="user-mention" data-user-id="281950">@Aman Arora</span> non-zero variants arise from pattern matching, yes. To be honest, I'm not sure if this will arise in closures. I think maybe it you use the older <code>ref</code> form of patterns, perhaps with an example like this...</p>
<div class="codehilite"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="nb">String</span>::<span class="n">new</span><span class="p">());</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="k">ref</span><span class="w"> </span><span class="n">q</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>the borrow that crates <code>q</code> would be from the <code>Same</code> variant. (<span class="user-mention" data-user-id="116118">@Matthew Jasper</span>, thoughts?)</p>
<p>The newer form of that <code>if let</code> (<code>if let Some(q) = &amp;p</code>) would first borrow <code>p</code> as a whole, I think, and so we wouldn't consider to only borrow "some part" of <code>p</code>. That is sort of interesting actually. =)</p>



<a name="202675296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202675296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202675296">(Jul 02 2020 at 11:21)</a>:</h4>
<p>That sounds right. Closures have to borrow the whole enum either way, because we don't know which variant is active for the enum when we create the closure.<br>
There are some ways to borrow from inside an enum without writing <code>ref</code>: <code>if let Some(A { x }) = Some(&amp;A { x: 2 })</code> borrows <code>(*(tmp.(Some.0))).x</code>.</p>



<a name="202675400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202675400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202675400">(Jul 02 2020 at 11:22)</a>:</h4>
<p>Although I think when we match on something the expr use visitor currently records a borrow of all of it, because we don't have a way to represent the tag of an enum.</p>



<a name="202675671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202675671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202675671">(Jul 02 2020 at 11:26)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/3659406c513062c265f8d8631fa8dae2702bbe8d/src/librustc_typeck/expr_use_visitor.rs#L203">https://github.com/rust-lang/rust/blob/3659406c513062c265f8d8631fa8dae2702bbe8d/src/librustc_typeck/expr_use_visitor.rs#L203</a></p>



<a name="202692294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202692294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202692294">(Jul 02 2020 at 14:03)</a>:</h4>
<p>Yeah, so, we already can't always borrow the precise path (e.g., slices), and I think that borrowing always the entire enum is fine</p>



<a name="202692322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202692322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202692322">(Jul 02 2020 at 14:03)</a>:</h4>
<p>but either way we probably want <code>Place</code> to have variant index</p>



<a name="202692326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202692326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202692326">(Jul 02 2020 at 14:03)</a>:</h4>
<p>kind of separate questions</p>



<a name="202694453"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202694453" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202694453">(Jul 02 2020 at 14:19)</a>:</h4>
<p>To generate the place for the enum access- will we be doing that while handling PatKind::TupleStruct? </p>
<p>And if so how do get the variant indeed and field information? Will it come from subpat_ty?</p>
<p><a href="https://github.com/rust-lang/rust/blob/9491f18c5de3ff1c4bf9c3fdacf52d9859e26f7c/src/librustc_typeck/mem_categorization.rs#L657">https://github.com/rust-lang/rust/blob/9491f18c5de3ff1c4bf9c3fdacf52d9859e26f7c/src/librustc_typeck/mem_categorization.rs#L657</a></p>



<a name="202694797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202694797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202694797">(Jul 02 2020 at 14:21)</a>:</h4>
<p>both <code>PatKind::TupleStruct</code> and <code>PatKind::Struct</code></p>



<a name="202694827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202694827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202694827">(Jul 02 2020 at 14:22)</a>:</h4>
<p>let me find the answer the other part of your question...</p>



<a name="202695049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202695049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202695049">(Jul 02 2020 at 14:23)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/9491f18c5de3ff1c4bf9c3fdacf52d9859e26f7c/src/librustc_mir_build/hair/pattern/mod.rs#L622-L630">this is the code that builds the HAIR</a></p>



<a name="202695204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202695204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202695204">(Jul 02 2020 at 14:24)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/9491f18c5de3ff1c4bf9c3fdacf52d9859e26f7c/src/librustc_mir_build/hair/pattern/mod.rs#L617">this code identifies the variant</a></p>



<a name="202695287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202695287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202695287">(Jul 02 2020 at 14:25)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/9491f18c5de3ff1c4bf9c3fdacf52d9859e26f7c/src/librustc_mir_build/hair/pattern/mod.rs#L720">this code computes the variant index</a></p>



<a name="202695292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202695292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202695292">(Jul 02 2020 at 14:25)</a>:</h4>
<p>so yeah some combination of those calls :)</p>



<a name="202696570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202696570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202696570">(Jul 02 2020 at 14:34)</a>:</h4>
<p>Thank you</p>



<a name="202860994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/202860994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#202860994">(Jul 04 2020 at 07:11)</a>:</h4>
<p>When using <code>span_bug!</code> how to we handle error codes? </p>
<p>We are trying to use it here: <a href="https://github.com/sexxi-goose/rust/blob/expand_projection_kinds/src/librustc_typeck/mem_categorization.rs#L653">https://github.com/sexxi-goose/rust/blob/expand_projection_kinds/src/librustc_typeck/mem_categorization.rs#L653</a></p>
<p>In case of <br>
<a href="https://github.com/rust-lang/rust/blob/9491f18c5de3ff1c4bf9c3fdacf52d9859e26f7c/src/test/ui/issues/issue-38412.rs">https://github.com/rust-lang/rust/blob/9491f18c5de3ff1c4bf9c3fdacf52d9859e26f7c/src/test/ui/issues/issue-38412.rs</a><br>
<a href="https://github.com/rust-lang/rust/blob/9491f18c5de3ff1c4bf9c3fdacf52d9859e26f7c/src/test/ui/issues/issue-38412.stderr">https://github.com/rust-lang/rust/blob/9491f18c5de3ff1c4bf9c3fdacf52d9859e26f7c/src/test/ui/issues/issue-38412.stderr</a></p>
<p>Our error text looks similar but is formatted weirdly </p>
<div class="codehilite"><pre><span></span><code>{&quot;message&quot;:&quot;expected tuple struct or tuple variant, found struct `Box`&quot;,&quot;code&quot;:{&quot;code&quot;:&quot;E0532&quot;,&quot;explanation&quot;:&quot;Pattern arm did not match expected kind.\n\nErroneous code example:\n\n```compile_fail,E0532\nenum State {\n    Succeeded,\n    Failed(String),\n}\n\nfn print_on_failure(state: &amp;State) {\n    match *state {\n        // error: expected unit struct, unit variant or constant, found tuple\n        //        variant `State::Failed`\n        State::Failed =&gt; println!(\&quot;Failed\&quot;),\n        _ =&gt; ()\n    }\n}\n```\n\nTo fix this error, ensure the match arm kind is the same as the expression\nmatched.\n\nFixed example:\n\n```\nenum State {\n    Succeeded,\n    Failed(String),\n}\n\nfn print_on_failure(state: &amp;State) {\n    match *state {\n        State::Failed(ref msg) =&gt; println!(\&quot;Failed with {}\&quot;, msg),\n        _ =&gt; ()\n    }\n}\n```\n&quot;},&quot;level&quot;:&quot;error&quot;,&quot;spans&quot;:[{&quot;file_name&quot;:&quot;/users/a52arora/rust/src/test/ui/issues/issue-38412.rs&quot;,&quot;byte_start&quot;:20,&quot;byte_end&quot;:23,&quot;line_start&quot;:2,&quot;line_end&quot;:2,&quot;column_start&quot;:9,&quot;column_end&quot;:12,&quot;is_primary&quot;:true,&quot;text&quot;:[{&quot;text&quot;:&quot;    let Box(a) = loop { };&quot;,&quot;highlight_start&quot;:9,&quot;highlight_end&quot;:12}],&quot;label&quot;:&quot;constructor is not visible here due to private fields&quot;,&quot;suggested_replacement&quot;:null,&quot;suggestion_applicability&quot;:null,&quot;expansion&quot;:null}],&quot;children&quot;:[],&quot;rendered&quot;:&quot;error[E0532]: expected tuple struct or tuple variant, found struct `Box`\n  --&gt; /users/a52arora/rust/src/test/ui/issues/issue-38412.rs:2:9\n   |\nLL |     let Box(a) = loop { };\n   |         ^^^ constructor is not visible here due to private fields\n\n&quot;}
{&quot;message&quot;:&quot;src/librustc_typeck/mem_categorization.rs:733:26: tuple struct pattern not applied to an ADT [type error]&quot;,&quot;code&quot;:null,&quot;level&quot;:&quot;error: internal compiler error&quot;,&quot;spans&quot;:[{&quot;file_name&quot;:&quot;/users/a52arora/rust/src/test/ui/issues/issue-38412.rs&quot;,&quot;byte_start&quot;:20,&quot;byte_end&quot;:26,&quot;line_start&quot;:2,&quot;line_end&quot;:2,&quot;column_start&quot;:9,&quot;column_end&quot;:15,&quot;is_primary&quot;:true,&quot;text&quot;:[{&quot;text&quot;:&quot;    let Box(a) = loop { };&quot;,&quot;highlight_start&quot;:9,&quot;highlight_end&quot;:15}],&quot;label&quot;:null,&quot;suggested_replacement&quot;:null,&quot;suggestion_applicability&quot;:null,&quot;expansion&quot;:null}],&quot;children&quot;:[],&quot;rendered&quot;:&quot;error: internal compiler error: src/librustc_typeck/mem_categorization.rs:733:26: tuple struct pattern not applied to an ADT [type error]\n  --&gt; /users/a52arora/rust/src/test/ui/issues/issue-38412.rs:2:9\n   |\nLL |     let Box(a) = loop { };\n   |         ^^^^^^\n\n&quot;}

.... More stuff ....
</code></pre></div>



<a name="203053110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053110">(Jul 06 2020 at 23:30)</a>:</h4>
<p><span class="user-mention" data-user-id="281950">@Aman Arora</span> <code>span_bug</code> is to be used only in the event of an internal compiler bug. It doesn't have any error codes?</p>



<a name="203053142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053142">(Jul 06 2020 at 23:31)</a>:</h4>
<p>in other words, if you're <em>testing</em> the output, it's not really an appropriate use of <code>span_bug</code></p>



<a name="203053148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053148">(Jul 06 2020 at 23:31)</a>:</h4>
<p>(i.e., we expect never to see that output)</p>



<a name="203053163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053163">(Jul 06 2020 at 23:31)</a>:</h4>
<p>this <em>may</em> be an appropriate case for <code>delay_span_bug</code></p>



<a name="203053220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053220">(Jul 06 2020 at 23:32)</a>:</h4>
<p>Give me one min</p>



<a name="203053221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053221">(Jul 06 2020 at 23:32)</a>:</h4>
<p>unfortunately I don't see any coverage of this in rustc-dev-guide</p>



<a name="203053242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053242">(Jul 06 2020 at 23:32)</a>:</h4>
<p>Copied this line here: <a href="https://github.com/rust-lang/rust/blob/9491f18c5de3ff1c4bf9c3fdacf52d9859e26f7c/src/librustc_mir_build/hair/pattern/mod.rs#L615">https://github.com/rust-lang/rust/blob/9491f18c5de3ff1c4bf9c3fdacf52d9859e26f7c/src/librustc_mir_build/hair/pattern/mod.rs#L615</a></p>



<a name="203053266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053266">(Jul 06 2020 at 23:33)</a>:</h4>
<p>the difference may be that</p>



<a name="203053272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053272">(Jul 06 2020 at 23:33)</a>:</h4>
<p>the HAIR construction code doesn't execute if they are type-checker errors</p>



<a name="203053274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053274">(Jul 06 2020 at 23:33)</a>:</h4>
<p>but the upvar inference <em>does</em></p>



<a name="203053281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053281">(Jul 06 2020 at 23:33)</a>:</h4>
<p>so that means that HAIR can assume that no errors were reported</p>



<a name="203053286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053286">(Jul 06 2020 at 23:33)</a>:</h4>
<p>this is why I mentioned <code>delay_span_bug</code> --</p>



<a name="203053290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053290">(Jul 06 2020 at 23:33)</a>:</h4>
<p>that basically is a method that says "it's a bug if you get to this code and no error was reported"</p>



<a name="203053298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053298">(Jul 06 2020 at 23:33)</a>:</h4>
<p>however, in that case, you still have to figure out what to <em>Do</em></p>



<a name="203053340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053340">(Jul 06 2020 at 23:34)</a>:</h4>
<p>i.e., where <code>span_bug</code> panics, <code>delay_span_bug</code> does not</p>



<a name="203053346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053346">(Jul 06 2020 at 23:34)</a>:</h4>
<p>in this case, generating some dummy place (perhaps an "error" place) would be appropriate</p>



<a name="203053350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053350">(Jul 06 2020 at 23:34)</a>:</h4>
<p>For the current test, we aren't doing any upvar analysis</p>



<a name="203053362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053362">(Jul 06 2020 at 23:34)</a>:</h4>
<p>see also <a href="https://rustc-dev-guide.rust-lang.org/ty.html?highlight=delay_span_bug#type-errors">this section of rustc-dev-guide</a></p>



<a name="203053370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053370">(Jul 06 2020 at 23:35)</a>:</h4>
<p>which does cover this general idea, albeit in a distinct context</p>



<a name="203053381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053381">(Jul 06 2020 at 23:35)</a>:</h4>
<p>well, regardless, the point is that you are reaching this point</p>



<a name="203053498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053498">(Jul 06 2020 at 23:37)</a>:</h4>
<p>Give me a bit to read</p>



<a name="203053532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053532">(Jul 06 2020 at 23:37)</a>:</h4>
<p>Okay delay_span_bug makes sense to me</p>



<a name="203053611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203053611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203053611">(Jul 06 2020 at 23:38)</a>:</h4>
<p>If I understand correctly -- it makes sense to do this in our case because this bug to be previously reported and that is since information around it was previously generated in typeck where the error would've been noticed</p>



<a name="203082532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203082532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203082532">(Jul 07 2020 at 09:25)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> <br>
Do we need Downcast and const index for our needs? <a href="https://github.com/rust-lang/project-rfc-2229/issues/1">https://github.com/rust-lang/project-rfc-2229/issues/1</a></p>
<p>or what is described <a href="https://github.com/rust-lang/project-rfc-2229/blob/master/hir-place-target.md">https://github.com/rust-lang/project-rfc-2229/blob/master/hir-place-target.md</a> enough?</p>
<p>IIRC for arrays  we don't care about which index we mark the whole array as captured, and down casts shoulnd't affect catpures</p>



<a name="203082610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203082610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203082610">(Jul 07 2020 at 09:26)</a>:</h4>
<p>And tuples get handled as fields</p>



<a name="203083043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203083043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203083043">(Jul 07 2020 at 09:32)</a>:</h4>
<p>Where <code>ConstIndex</code> is used in a MIR Place, we can use <code>Index</code>, since we  don't care about the index. <code>Downcast</code> is merged into field in the HIR place described.</p>



<a name="203084964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203084964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203084964">(Jul 07 2020 at 09:59)</a>:</h4>
<p>what do you mean by Downcast is merged into field?</p>



<a name="203086712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203086712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203086712">(Jul 07 2020 at 10:26)</a>:</h4>
<p>in MIR, we use "downcasting" to select the enum variant. So if you access (e.g.) the 0th field of the <code>Some</code> variant, you get a place like <code>foo.downcast&lt;Some&gt;.0</code> -- obviously this is not valid Rust syntax. </p>
<p><span class="user-mention silent" data-user-id="116118">Matthew Jasper</span> was proposing for HIR Places that we can just make that <code>foo.(Some:0)</code>, i.e., bake the variant (<code>Some</code>) into the projection itself.</p>
<p>I think that's fine, though I also think that if we like that more we should consider revising the MIR places to match.</p>



<a name="203086802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203086802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203086802">(Jul 07 2020 at 10:28)</a>:</h4>
<p>Similarly, <code>ConstIndex</code> is used for some special cases where we know the index is a fixed constant -- mostly pattern matching like <code>let [a, b, _] = some_array</code>.  The compiler is (sometimes) smart enough to see that these moves are distinct from (say) <code>let [_, _, c] = some_array</code>, but to be that smart, it needs to know the indices as constants. We I think are just going to capture the entire array for now, so we don't care for now.</p>



<a name="203330110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203330110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203330110">(Jul 08 2020 at 22:11)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/enum.PatKind.html#variant.Tuple">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/enum.PatKind.html#variant.Tuple</a><br>
When it says <code>dots_pos &lt;= subpats.len()</code>,  is it trying to refer to the total number of fields for the Tuple? </p>
<p>Even in the case where <code>if let (a, b, ..) = (1, 2)</code> , the subpats count = 3. dots_pos = 2</p>



<a name="203360541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/203360541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#203360541">(Jul 09 2020 at 08:14)</a>:</h4>
<p>Nvm looked up ast_lowering subpats acutally don't contain the dots</p>



<a name="221105874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/221105874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#221105874">(Dec 29 2020 at 01:59)</a>:</h4>
<p>So the original spec for ProjectionKind::Field expresses the field index as a <code>u32</code> instead of <code>usize</code>. I'm wondering if there is a specific reason behind it? I see that everywhere it's used in code we have to cast around it because fields are expressed using <code>usize</code> everywhere.</p>



<a name="221224780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds/near/221224780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/ProjectionKinds.html#221224780">(Dec 30 2020 at 16:29)</a>:</h4>
<p><span class="user-mention" data-user-id="281950">@Aman Arora</span> no real reason, just to save memory</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>